<template>
	<view>
		<view class="stage" @click="openPicker">
			<view class="name">
				跟进阶段
			</view>
			<view class="info">
				{{stage}}
			</view>
			<uv-icon name="arrow-right" color="#BEBEBE" size="30rpx"></uv-icon>
		</view>
		<view class="textarea">
			<uv-textarea v-model="textarea" height="300rpx" border="none" placeholder="添加跟进内容（1000字以内）"></uv-textarea>
			<view class="upload_photo">
				<uv-upload
					:fileList="fileList1"
					name="1"
					multiple 
					:maxCount="10"
					@afterRead="afterRead" 
					@delete="deletePic" 
				></uv-upload>
			</view>
		</view>
		
		
		<view class="stage" @click="openDatetime">
			<view class="name">
				下次跟进时间
			</view>
			<view class="info">
				
			</view>
			<uv-icon name="arrow-right" color="#BEBEBE" size="30rpx"></uv-icon>
		</view>
		
		<view class="foot_org_btn">
			完成
		</view>
		
		<uv-picker ref="picker" :columns="columnsPicker" @confirm="confirmPicker"></uv-picker>
		
		<uv-datetime-picker ref="datetimePicker" v-model="nextTime" mode="datetime" @confirm="confirmDatetime">
		</uv-datetime-picker>
				
	</view>
</template>

<script>
	export default {
		data() {
			return {
				textarea:'',
				fileList1: [],
				columnsPicker: [
					['跟进阶段','建立阶段','确认意向','承诺到访','预约试听','完成试听','完成缴费']
				],
				stage:'',
				nextTime: Number(new Date()),
			}
		},
		onLoad() {

		},
		methods: {
			openDatetime() {
				this.$refs.datetimePicker.open();
			},
			confirmDatetime(e) {
				console.log('confirmDatetime', e);
			},
			openPicker() {
				this.$refs.picker.open();
			},
			confirmPicker(e){
				//console.log(e.value[0])
				this.stage = e.value[0]
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.foot_org_btn{
	position: fixed;
	left:0;
	bottom: 0;
	right: 0;
	margin: 40rpx 40rpx 60rpx;
	color: #fff;
	height: 84rpx;
	border-radius: 8rpx;
	background: #FF8535;
	line-height: 84rpx;
	text-align: center;
	font-size: 30rpx;
}
.textarea{
	padding: 10rpx 25rpx;
	background: #fff;
	.upload_photo{
		padding:20rpx;
	}
}
.stage{
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 100rpx;
	padding:0 40rpx;
	background: #F7F7F9;
	.name{
		font-size: 30rpx;
		line-height: 42rpx;
		color: #1A1A1A;
		flex-shrink: 0;
	}
	.info{
		width: 100%;
		text-align: right;
		font-size: 28rpx;
		line-height: 42rpx;
		color: #555;
		padding-right: 10rpx;
		box-sizing: border-box;
	}
	&:last-child{
		border-bottom: 1px solid #eee;
	}
}
</style>
